package com.kimehwa.studyboot.elasticsearchtest;

import org.apache.http.HttpHost;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @author xiaodongguan
 * @description
 * @since 2021-09-21 14:47
 */

public class EstestUpdate {
    /*
    增删改查都是要他进行搞起
     */
    public static void main(String[] args) throws IOException {

        // 创建es对象
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("47.105.163.178",9200,"http"))
        );

        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.index("user").id("1001");
        updateRequest.doc(XContentType.JSON,"sex","女");


        UpdateResponse response = esClient.update(updateRequest, RequestOptions.DEFAULT);

        System.out.println(response.getResult());


        esClient.close();



    }
}
